import Mock from 'mockjs'
import { getResponse, api, pageJson } from './tools'

const operationTable = Mock.mock({
  'tableDatas|10': [
    {
      id: '@integer(1,10)',
      goodName: '@ctitle',
      qty: '@integer(10,1000) ',
      money: '@float(100,10000)'
    }
  ],
  'inventoryTable|33': [
    {
      id: '@integer(1,10)',
      'amount|1-99999': 0.01,
      goodsName: '@cword(3,6)',
      'index|+1': 0,
      'qty|0-9999': 1
    }
  ]
})

const topList = {
  monthBuyAmount: '111',
  monthBuyOrderPrice: '222',
  monthBuyOrderTotal: '333',
  monthBuySupplierPrice: '444',
  monthBuySupplierTotal: '555',
  yesterdayBuyAmount: '666'
}

export default [
  // table1
  {
    url: api.operationTable,
    type: 'get',
    response: config => {
      const tableData = operationTable.tableDatas
      return {
        code: '000000',
        retData: {
          records: tableData,
          total: tableData.length
        }
      }
    }
  },
  // table2
  {
    url: api.inventoryData,
    type: 'get',
    response: config => {
      return pageJson(operationTable.inventoryTable, {}, [
        {
          key: 'amount',
          name: '商品金额'
        },
        {
          key: 'goodsName',
          name: '商品名称'
        },
        {
          key: 'index',
          name: '序号'
        },
        {
          key: 'qty',
          name: '商品数量'
        }
      ])
    }
  },
  {
    url: api.inventoryChart,
    type: 'get',
    response: config => {
      return getResponse({ retData: topList })
    }
  }
]
